const fs = require('fs');
const path = require('path');
const mysql = require('mysql2/promise');
const config = require('../config/db');

async function runMigration() {
  try {
    console.log('Running gas station migration...');
    
    // Read the SQL file
    const sqlPath = path.join(__dirname, '../migrations/add_gas_card_balance_to_users.sql');
    const sql = fs.readFileSync(sqlPath, 'utf8');
    
    // Create database connection
    const connection = await mysql.createConnection({
      host: config.host,
      user: config.user,
      password: config.password,
      database: config.database,
      multipleStatements: true // Important for running multiple SQL statements
    });
    
    // Execute the SQL statements
    await connection.query(sql);
    
    console.log('Gas station migration completed successfully!');
    
    // Close the connection
    await connection.end();
    process.exit(0);
  } catch (error) {
    console.error('Error running migration:', error);
    process.exit(1);
  }
}

runMigration(); 